<?php

declare (strict_types=1);

namespace app\bbxw\controller;


use think\admin\Controller;

/**
 * 用户前台
 * @class Package
 * @package app\bbxw\controller
 */
class Customermain extends Controller
{

    /**
     * 绑定数据表
     * @var string
     */
    private $table = 'play_accompany';
    /**
     * 登录
     */
    public function login()
    {
        if($this->request->isPost()){
            $data = $this->request->post();
            $customer = $this->app->db->name("customer")->where('name',$data['name'])->find();
            if(empty($customer)){
                $this->error('用户不存在');
            }
            if($customer['password'] != md5($data['password'])){
                $this->error('账号或密码错误');
            }
            session('customer',$customer);
            $this->success('登录成功',sysuri('bbxw/customermain/index'));
        }else{
            $this->fetch();
        }


    }

    public function index(){
        $this->title='账单查询';

        if(empty(session('customer'))){
            $this->error('请先登录',sysuri('bbxw/customermain/login'));
        }
        $this->customer = $this->app->db->name("customer")->field('id,name,prestore_amount,use_amount')->find(session('customer')['id']);
        $query = $this->_query($this->table);
        // 列表排序并显示
        $query->like('activity_gift')->order('id desc')->page();
        $this->fetch();
    }

    /**
     * 图文列表数据处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _page_filter(array &$data)
    {


    }


    /**
     * 添加套餐
     * @auth true
     */
    public function add()
    {
        $this->_form($this->table, 'form');
    }

    /**
     * 表单数据处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _form_filter(array &$data)
    {

    }
    /**
     * 编辑套餐
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function edit()
    {
        $this->_form($this->table, 'form');
    }

    public function backOrder()
    {
        $this->_form($this->table, 'back_order');
    }
    /**
     * 删除套餐
     * auth true
     */
    public function remove()
    {
        $this->_delete($this->table);
    }

}